#include "defines.hpp"

Inimigo::Inimigo()
{
    this->x = 0.0f;
    this->y = 0.0f;
    this->z = 0.0f;
	this->status = 1;  // vivo
	this->cx = 0.05f;
	this->cy = 0.05f;
	this->cz = 0.05f;
	this->bx = 0.0f;
	this->by = 0.0f;
	this->bz = 0.0f;
}

Inimigo::Inimigo(float bx, float by, float bz){
  this->x = 0;
  this->y = 0;
  this->z = 0;
  this->status = 1;
  this->cx = 0.05f;
  this->cy = 0.05f;
  this->cz = 0.05f;
  this->bx = bx;
  this->by = by;
  this->bz = bz;
}

Inimigo::Inimigo(float bx, float by, float bz, float cx, float cy, float cz){
  this->x = 0;
  this->y = 0;
  this->z = 0;
  this->status = 1;
  this->cx = cx;
  this->cy = cy;
  this->cz = cz;
  this->bx = bx;
  this->by = by;
  this->bz = bz;
  this->naveInimigo = NULL;
}

GLMmodel* drawmodelo(char *string, char *type)
{
    GLMmodel* pmodel = NULL;
    if (!pmodel) {
        pmodel = glmReadOBJ(string);
        if (!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel, 90.0);

    }     

return pmodel;
}

void Inimigo::Desenha(){
   //glRotatef(180,1,0,0);
   //glRotatef(90,0,0,1);
   //glScalef(0.1,0.1,0.1);
   //naveInimigo=drawmodelo("modelos/phoenix.obj","texture");
   //glmDraw(naveInimigo, GLM_SMOOTH);


   
   if (status == 1){ // se esta vivo
	  glLoadIdentity();
	  glTranslatef(bx+x,by+y,bz+z);
	  glBegin(GL_LINE_LOOP);
        glVertex3f(cx,cy,cz);
        glVertex3f(-cx,cy,cz);
        glVertex3f(-cx,-cy,cz);
	    glVertex3f(cx,-cy,cz);
      glEnd();
   
      glBegin(GL_LINE_LOOP);
        glVertex3f(cx,cy,-cz);
        glVertex3f(-cx,cy,-cz);
        glVertex3f(-cx,-cy,-cz);
	    glVertex3f(cx,-cy,-cz);
      glEnd();

      glBegin(GL_LINE);
       glVertex3f(cx,cy,-cz);
	   glVertex3f(cx,cy,cz);

	   glVertex3f(-cx,cy,cz);
	   glVertex3f(-cx,cy,-cz);

	   glVertex3f(-cx,-cy,cz);
	   glVertex3f(-cx,-cy,-cz);

	   glVertex3f(cx,-cy,cz);
	   glVertex3f(cx,-cy,-cz);
     glEnd();
   }
}

bool Inimigo::Colisao(Projetil projetil){
	if(((projetil.GetY() -by -y) < cy)&&(-cy  < (projetil.GetY() -by -y)))
		if ((-cx  < (projetil.GetX() -bx -x))&&((projetil.GetX() -bx -x) < cx))
			 if((-cz  < (projetil.GetZ() -bz -z))&&( (projetil.GetZ() -bz -z) < cz)){
				status = 0; // morto
				return true;
	}
	return false;
}

float Inimigo::getX(){
  return this->bx+x;
}

float Inimigo::getY(){
  return this->by+y;
}

float Inimigo::getZ(){
  return this->bz+z;
}

void Inimigo::SetX(float novoX){
 x = novoX;
}

void Inimigo::SetY(float novoY){
 y = novoY;
}

void Inimigo::SetZ(float novoZ){
 z = novoZ;
}

Projetil Inimigo::Atira(){
        Projetil p = Projetil( bx+ x, by+ y-0.1,bz+z);
		p.Desenha();
        glutPostRedisplay();
		return p;
}

Inimigo::~Inimigo()
{
}
